#ifndef _XML_MANAGER_H_
#define _XML_MANAGER_H_

#include "tinyxml.h"
#include "Tracker.h"
#include <list>
#include <string>
#include <vector>

#define DETECTION	1	//Const for DoT value.
#define GROUNDTRUTH 4	//Const for DoT value. Could be connected to DATReader

class XMLManager
{
public:
	XMLManager()
	{
		mRootNode = NULL;
		mCurrentFrameNode = NULL;
		mCurrentFrame = 0;
	};
	~XMLManager()
	{
		//if(mRootNode) 
		//	delete mRootNode;
		//if(mCurrentFrameNode) 
		//	delete mCurrentFrameNode;
	};

	bool openFile(std::string inFilename, bool inEraseFile = true);
	bool init(unsigned int inNbFrame = 0);	//Fill it with inNbFrame (not if <= 0)

	//One frame at a time (NEXT)
	bool saveFrame(const std::list<Tracker*>& inUpdatedTrackers, bool inEraseFrame = true);
	bool saveFrame(const std::list<Tracker*>& inUpdatedTrackers, int inFrame, bool inEraseFrame = true);

	//DoT == 4 --> Groundtruth
	bool saveFrame(const std::list<DATObject*>& inObjects, bool inEraseFrame = true, bool inGroundTruth = true);
	bool saveFrame(const std::list<DATObject*>& inObjects, int inFrame, bool inEraseFrame = true, bool inGroundTruth = true);

	//All frame (good luck with that)
	bool saveAllFrames(const std::list<list<Tracker*> >& inAllUpdatedTrackers){return false;}; //Not implemented yet
	bool saveAllFrames(const std::list<list<DATObject*> >& inAllObjects){return false;}; //Not implemented yet

	//Change the attritube of an object at a specific frame
	//For a better use, if you got to change more then one frame at a time, start with the history, finish with current
	bool changeAttributeValue(int inObjectID, int inFrame,std::string inElementName, std::string inAttribute, std::string inValue);
	
	//Change the ID value of an object at a specific frame
	bool changeIDValue(int inObjectToChangeID, int inNewObjectID, int inFrame);

	//For stupid error...
	bool XMLManager::changeFrameAttributeValue(int inFrame, std::string inValue);
private:
	//Yeah, its fully inside it. FUCK OFF.
	TiXmlDocument	mXMLDocument;
	TiXmlNode*		mRootNode;
	TiXmlElement*	mCurrentFrameNode;

	unsigned int	mCurrentFrame;
};

#endif